<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改人员主数据')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-employee-edit">
        <input id="id" name="id" type="hidden" th:value="${employee.id}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">工号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="jobNumber" placeholder="请输入工号" th:value="${employee.jobNumber}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">姓名：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" placeholder="请输入人员姓名" th:value="${employee.name}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">职级：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="jobGrade" placeholder="请输入职级" th:value="${employee.jobGrade}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">上级领导：</label>
            <div class="col-sm-8">
                <select name="reportTo" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="reportTo : ${reportTo}" th:text="${reportTo.employeeCN}"
                            th:value="${reportTo.id}" th:selected="${reportTo.id==employee.reportTo}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">部门：</label>
            <div class="col-sm-8">
                <select name="deptId" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="department : ${department}" th:text="${department.deptCN}"
                            th:value="${department.id}" th:selected="${department.id==employee.deptId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">岗位：</label>
            <div class="col-sm-8">
                <select name="postId" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="post : ${post}" th:text="${post.postName}"
                            th:value="${post.id}" th:selected="${post.id==employee.postId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="check-box" th:each="dict : ${@dict.getType('emp_status')}">
                    <input type="radio" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.dictValue==employee.status+''}"
                           th:text="${dict.dictLabel}">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">邮箱：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="email" placeholder="请输入邮箱" th:value="${employee.email}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">身份证号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="idCard" placeholder="请输入身份证号" th:value="${employee.idCard}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">电话：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="phone" placeholder="请输入电话" th:value="${employee.phone}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">性别：</label>
            <div class="col-sm-8">
                <div class="check-box" th:each="dict : ${@dict.getType('sys_user_sex')}">
                    <input type="radio" name="gender" th:value="${dict.dictValue}"
                           th:checked="${dict.dictValue==employee.gender+''}"
                           th:text="${dict.dictLabel}">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出生日期：</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="birthday" placeholder="出生日期" name="birthday"
                       th:value="${employee.birthday}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">入职日期：</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="joinTime" placeholder="入职日期" name="joinTime"
                       th:value="${employee.joinTime}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">离职日期：</label>
            <div class="col-sm-6">
                <input type="text" class="form-control" id="leaveTime" placeholder="离职日期" name="leaveTime"
                       th:value="${employee.leaveTime}">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "employee";

    $(function () {
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            laydate.render({
                elem: '#birthday'
            });

            laydate.render({
                elem: '#joinTime'
            });

            laydate.render({
                elem: '#leaveTime'
            });
        });
    });

    $("#form-employee-edit").validate({
        rules: {
            onkeyup: false,
            jobNumber: {
                remote: {
                    url: prefix + "/checkNumberUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "jobNumber": function () {
                            return $("input[name='jobNumber']").val();
                        },
                        "id": function () {
                            return $("input[name='id']").val();
                        },
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            name: {
                isName: true
            },
            email: {
                email: true
            },
            idCard: {
                isIdentity: true
            },
            phone: {
                isPhone: true
            },
            birthday: {
                isBirth: true
            }
        },
        messages: {
            "jobNumber": {
                remote: "工号已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-employee-edit").serializeArray();
            $.operate.save(prefix + "/edit", data);
        }
    }

</script>
</body>
</html>